/**   
 * @copyright Copyright (c) IKongJian Inc. 2015 All Rights Reserved.
 * @Title: HtmlUtil.java 
 * @Package com.ikongjian.commons.util 
 * @Description: html 工具类  
 * @author ZHAOCHENGJU ZHAOCHENGJU@163.COM   
 * @date 2015年8月5日 上午10:56:29 
 * @version V1.0   
 */ 
  
package com.li.commons.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** 
 * @ClassName: HtmlUtils 
 * @Description: 对html文本做一些操作 
 * @author ZHAOCHENGJU ZHAOCHENGJU@163.COM
 * @date 2015年8月5日 上午10:56:29 
 * @since JDK 1.7 
 * @see       
 */
public class HtmlUtils {
	
	/**
	 * 去除html、script、style标签
	 * @Title: delHtmlTag
	 * @Description: 去除html标签
	 * @param content
	 * @return 返回去除完标签的文本
	 * @author: ZHAOCHENGJU
	 * @date 2015年8月5日 上午11:02:55
	 */
	public static String delHtmlTag(String content) {
		String regExRemark = "<!--.+?-->";
		String regExScript = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
		String regExStyle = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
		String regExHtml = "<[^>]+>";
		String regExHtml1 = "<[^>]+";
		content = content.replaceAll("\n", "");
		content = content.replaceAll("\t", "");
		// 过滤注释标签
		Pattern pattern = Pattern.compile(regExRemark, Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(content);
		content = matcher.replaceAll("");
		// 过滤html标签
		pattern = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
		matcher = pattern.matcher(content);
		content = matcher.replaceAll("");
		pattern = Pattern.compile(regExHtml1, Pattern.CASE_INSENSITIVE);
		matcher = pattern.matcher(content);
		content = matcher.replaceAll("");
		// 过滤script标签
		pattern = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
		matcher = pattern.matcher(content);
		content = matcher.replaceAll("");
		// 过滤style标签
		pattern = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
		matcher = pattern.matcher(content);
		content = matcher.replaceAll("");
		return content.trim();
	}
}
  